#include "txtuserreader.h"
#include <QApplication>
txtuserreader::txtuserreader(QString connStr):AbstractUserReader(connStr)
{
    this->path = connStr;
}

QList<User*> *txtuserreader::readUsers()
{
    QList<User*>* users = new QList<User*>;
    QString fp = QApplication::applicationDirPath()+"\\"+path;
    QFile file(fp);

    if(file.open(QFile::ReadOnly | QFile::Text))
    {
        QTextStream in(&file);
        QString line = in.readLine();

        while (!line.isNull())
        {
            QRegExp rx("(\\;|\\=)|\\,");
            QStringList list = line.split(rx);
            User* tmpUser = new User (list[1]);
            for (int i = 3; i < list.count(); i++)
                tmpUser->add_card(list[i].toInt());
            users->push_back(tmpUser);

            line = in.readLine();
        }

        return users;
    }
}
